﻿using mediaControl.Utils;
using mediaControl.Vo;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace mediaControl.ViewModels
{
    public class WebpageViewModel : BindableBase, IDialogAware
    {
        public WebpageViewModel()
        {
            ConfirmCommand = new DelegateCommand(confirm);
        }

        public ObservableCollection<ScreenItemVo> ScreenItemVos { get { return screenItemVos; } set { screenItemVos = value; RaisePropertyChanged(); } }

        private ObservableCollection<ScreenItemVo> screenItemVos = new ObservableCollection<ScreenItemVo>();

        private ProgramItem programItem;

        private ProgramVo selectedItem;

        //项目类型 1 视频，2图片，3文件夹，4网页内容，5采集卡，6电脑桌面，7黑场颜色
        private String itemType;

        //项目路径
        private String itemPath;

        //显示模式
        private String displayMode;

        //播放模式
        private String playMode;

        private List<String> screens;

        private bool isLink = false;

        private int residenceTime;

        private void confirm()
        {
            if (String.IsNullOrEmpty(ItemPath))
            {
                MessageBox.Show("网页地址不能为空！");
                return;
            }
            IDialogParameters parameters = new DialogParameters();
            parameters.Add("itemPath", ItemPath);
            RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK, parameters));
        }

        public DelegateCommand ConfirmCommand { get; set; }

        public string Title { get; set; }
        public ProgramItem ProgramItem { get => programItem; set => programItem = value; }
        public ProgramVo SelectedItem { get => selectedItem; set => selectedItem = value; }
        public string ItemType { get => itemType; set => itemType = value; }
        public string ItemPath { get { return itemPath; } set { this.itemPath = value; RaisePropertyChanged(); } }
        public string DisplayMode { get { return displayMode; } set { this.displayMode = value; RaisePropertyChanged(); } }
        public string PlayMode { get { return playMode; } set { playMode = value; RaisePropertyChanged(); } }
        public List<string> Screens { get => screens; set => screens = value; }
        public bool IsLink { get { return isLink; } set { isLink = value; RaisePropertyChanged(); } }
        public int ResidenceTime { get { return residenceTime; } set { this.residenceTime = value; RaisePropertyChanged(); } }

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            Title = "设置网页";
        }
    }
}
